package com.azunitech.jms.repos;

import java.util.ArrayList;
import java.util.Collection;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;



@Entity
@Table(name="Parts")
public class Parts {
	@Id
	private String id;
	
	@OneToMany(targetEntity=Location.class, mappedBy="parts")
    private Collection<Location> locations;

	public Parts() {
		 locations = new ArrayList<Location>();
	}

    public String getId() {
        return id;
    }
    
    public void setId(String id) {
        this.id = id;
    }
    
    public void addLoction(Location location) {
        if (!getLocations().contains(location)) {
        	getLocations().add(location);
            if (location.getParts() != null) {
            	location.getParts().getLocations().remove(location);
            }
            location.setParts(this);
        }
    }
    
    public Collection<Location> getLocations() {
        return locations;
    }

    public String toString() {
        return "Department id: " + getId();
    }    
}
